﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using JsonTest1.Data;
using Newtonsoft.Json.Linq;

namespace JsonTest1.Json
{
    public class LicenseBuilder: JSONBuilder<License>
    {

        public override License Build(JObject jsonObject)
        {
            License license = new License();
            license.Image = (string)jsonObject["image"];
            license.Url = (string)jsonObject["url"];
            license.Id = (int)jsonObject["id"];
            return license;
        }

        public  License Build(string json)
        {
            JArray jsonArray = JArray.Parse(json);
            if (jsonArray.Count > 0)
            {
                JObject jsonObject = (JObject)jsonArray[0];
                License license = new License();
                license.Image = (string)jsonObject["image"];
                license.Url = (string)jsonObject["url"];
                license.Id = (int)jsonObject["id"];
                return license;   
            }
            return null;
        }
    }
}
